# -*- codeing = utf-8 -*-
# @Time : 2021/2/22 16:34
# @Atuthor: 朱朱
# @File: 044列表冒泡排序.py
# @Software: PyCharm
# 冒泡排序思想:
# 让一个数字和它相邻的下一个数字进行比较运算
# 如果前一个数字大于后一个数字，交换两个数据的位置
nums = [6, 5, 3, 1, 8, 7, 2, 4]
# k=0
# while k<len(nums)-1:
#     k+=1
#     for i in range(len(nums)):
#         if i<len(nums)-k:
#             if nums[i+1]>nums[i]:
#                 nums[i],nums[i+1]=nums[i+1],nums[i]
# print(nums)

# -----------------------------
# 每一趟比较次数的优化
# 总比较趟数的优化
i = 0
while i<len(nums)-1:
    i+=1
    n = 0
    while n <len(nums)-1:
        if  nums[n]>nums[n+1]:
            nums[n],nums[n+1]=nums[n+1],nums[n]
        n+=1
    print(nums)

